package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
	yaml "gopkg.in/yaml.v3"
	"log"
	"net/http"
	"os"
	"test/model"
	"test/util"
)

func main() {
	//http.HandleFunc("/", indexHandler)
	//port := os.Getenv("PORT")
	//if port == "" {
	//	port = "8080"
	//	log.Printf("Defaulting to port %s", port)
	//}
	//log.Printf("Listening on port %s", port)
	//log.Printf("Open http://localhost:%s in the browser", port)
	//log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))

	conf := new(model.Config)
	var file, _ = os.ReadFile("test.yaml")
	log.Println("file:", string(file))
	_ = yaml.Unmarshal(file, conf)
	log.Println("conf", fmt.Sprintf("%s", conf))
	var jsonStr, err = json.Marshal(conf)
	if err != nil {
		log.Fatalln("json异常转换", err)
	}
	log.Println("jsonStr1", jsonStr)
	log.Println("jsonStr2", string(jsonStr))

	var ns = []int{1, 2, 3}
	ns[0] = 2
	ns = append(ns, 123)
	for i := range ns {
		log.Println("i,ns[i]", i, ns[i])
	}

	log.Println("ns", len(ns))
	var xmlStr, _ = xml.Marshal(conf)
	log.Println("xmlStr1", xmlStr)
	log.Println("xmlStr2", string(xmlStr))

	var ls = util.Array{}
	var ls1 = util.Array{}

	ls = util.Append(ls, 2)
	log.Println("ls", ls, ls1)
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}
	_, err := fmt.Fprint(w, "Hello, World!")
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
	}
}
